const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const config = {
  devServer: {
    static: {
      directory: path.join(__dirname, "dist"),
    },
    host: "192.168.100.51",
    compress: true,
    port: 3006,
  },
  mode: "development",
  entry: path.join(__dirname, "src/main.ts"),
  output: {
    filename: "bundle[hash].js",
    path: path.join(__dirname, "dist"),
    library: {
      name: "EditorCanvas",
      type: "umd",
      export: "default",
    },
  },
  devtool: "source-map",
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        loader: "ts-loader",
      },
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.scss$/,
        use: ["style-loader", "css-loader", "sass-loader"],
      },
      {
        test: /\.(gif|jpg|jpeg|png|svg)$/,
        type: "asset/resource",
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
        loader: "file-loader",
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js", ".json"],
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "index.html",
      inject: true,
    }),
  ],
};
module.exports = config;
